package learn.design.patterns.B_Prototype;

import java.io.IOException;

public class TestClass {
    public static void main(String[] args) {
        Prototype prototype1 = new Prototype("Prototype1");
        Prototype shallowCopy = null;
        Prototype deepCopy = null;
        try {
            shallowCopy = (Prototype) prototype1.clone();
            deepCopy = prototype1.deepClone();
        } catch (IOException | ClassNotFoundException | CloneNotSupportedException e) {
            e.printStackTrace();
        }

        // 修改原型对象
        prototype1.getList().add("New Item");

        // 输出结果
        System.out.println("Original Prototype: " + prototype1.getData());
        System.out.println("Shallow Copy: " + shallowCopy.getData());
        System.out.println("Deep Copy: " + deepCopy.getData());

        // 检查列表是否被复制
        System.out.println("Original List: " + prototype1.getList());
        System.out.println("Shallow Copy List: " + shallowCopy.getList());
        System.out.println("Deep Copy List: " + deepCopy.getList());
    }
}
